//
//  KongWFindDoctorTableViewCell.m
//  LoveOfPet
//
//  Created by dllo on 15/11/14.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "KongWFindDoctorTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
#define kHeight     [UIScreen mainScreen].bounds.size.height / 667
#define kWidth      [UIScreen mainScreen].bounds.size.width / 375
@implementation KongWFindDoctorTableViewCell
-(void)dealloc
{
    [_backView release];
    [_findDoctorModel release];
    [_img release];
    [_nameLabel release];
    [_scoreLabel release];
    [_jobLabel release];
    [_hospitalLabel release];
    [_distanceLabel release];
    [_introduceLabel release];
    [super dealloc];
}
-(instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubView];
    }
    return self;
}

-(void)creatSubView
{
    self.backView = [[UIView alloc] init];
    self.backView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.backView];
    [self.backView release];
    
    self.img = [[UIImageView alloc] init];
    self.img.layer.cornerRadius = 35;
    [self.backView addSubview:self.img];
    [self.img release];
    
    self.nameLabel = [[UILabel alloc] init];
    [self.backView addSubview:self.nameLabel];
    [self.nameLabel release];
    
    self.scoreLabel = [[UILabel alloc] init];
    self.scoreLabel.textColor = [UIColor redColor];
    [self.backView addSubview:self.scoreLabel];
    [self.scoreLabel release];
    
    self.jobLabel = [[UILabel alloc] init];
    self.jobLabel.textColor = [UIColor grayColor];
    [self.backView addSubview:self.jobLabel];
    [self.jobLabel release];
    
    self.hospitalLabel = [[UILabel alloc] init];
    self.hospitalLabel.textColor = [UIColor blueColor];
    [self.backView addSubview:self.hospitalLabel];
    [self.hospitalLabel release];
    
    self.distanceLabel = [[UILabel alloc] init];
    self.distanceLabel.font = [UIFont systemFontOfSize:15];
    [self.backView addSubview:self.distanceLabel];
    [self.distanceLabel release];

    self.introduceLabel = [[UILabel alloc] init];
    self.introduceLabel.numberOfLines = 2;
    self.introduceLabel.font = [UIFont systemFontOfSize:18];
    self.introduceLabel.textColor = [UIColor grayColor];
    [self.backView addSubview:self.introduceLabel];
    [self.introduceLabel release];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.backView.frame = CGRectMake(0, kHeight * 5, self.contentView.frame.size.width, self.contentView.frame.size.height - kHeight * 5);
    
    self.img.frame = CGRectMake(kWidth * 10, kHeight * 10, 70, 70);
    
    self.nameLabel.frame = CGRectMake(self.img.frame.origin.x + self.img.frame.size.width + 20, self.img.frame.origin.y, kWidth * 120, kHeight * 20);
    
    self.scoreLabel.frame = CGRectMake(self.nameLabel.frame.origin.x + self.nameLabel.frame.size.width + 30, self.nameLabel.frame.origin.y, kWidth * 30, kWidth * 20);
    
    self.jobLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height + 5, kWidth * 150, kWidth * 18);
    
    self.hospitalLabel.frame = CGRectMake(self.jobLabel.frame.origin.x, self.jobLabel.frame.origin.y + self.jobLabel.frame.size.height + kHeight * 5, self.jobLabel.frame.size.width, self.nameLabel.frame.size.height);
    
    self.distanceLabel.frame = CGRectMake(kWidth * (375 - 100), self.hospitalLabel.frame.origin.y, kWidth * 90, self.hospitalLabel.frame.size.height);
    
    self.introduceLabel.frame = CGRectMake(self.img.frame.origin.x, self.img.frame.origin.y + self.img.frame.size.height + 20, self.contentView.frame.size.width - kWidth * 20, kHeight * 50);
}

-(void)setFindDoctorModel:(KongWFindDoctorModel *)findDoctorModel
{
    if (_findDoctorModel != findDoctorModel) {
        [_findDoctorModel release];
        _findDoctorModel = [findDoctorModel retain];
    }
    
    [self.img sd_setImageWithURL:[NSURL URLWithString:findDoctorModel.avatar]];
    
    NSString *name = [findDoctorModel.name stringByReplacingOccurrencesOfString:@"<font color=\"#00a0e9\">" withString:@""];
    name =  [name stringByReplacingOccurrencesOfString:@"</font>" withString:@""];
    
    self.nameLabel.text = name;
    
    self.scoreLabel.text = [NSString stringWithFormat:@"%ld分", findDoctorModel.avg_score];
    
    self.jobLabel.text = findDoctorModel.job;
    
    self.hospitalLabel.text = findDoctorModel.hospital;
    
    self.distanceLabel.text = [NSString stringWithFormat:@"%.2fKm", (CGFloat)findDoctorModel.distance / 1000];
    
    self.introduceLabel.text = findDoctorModel.introduce;
}



























- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
